import { reqClickStar, reqChangeIsCollect } from '../../api/travelarticles'

const state = {
  isCollect: true
}

const actions = {
  //点收藏
  async changeMsg({ commit }) {
    let res = await reqClickStar()
    console.log(res)
    commit('CHANGE_MSG', res.data)
  },
  //一进来就查询
  async changeIsCollect({ commit }) {
    let res = await reqChangeIsCollect()
    commit('CHANGE_MSG', res.data.data.state)
  }
}
const mutations = {
  CHANGE_MSG(state, data) {
    if (data.msg === 'remove success') {
      state.isCollect = true
    } else {
      state.isCollect = false
    }
  },
  CHANGE_ISCOLLECT(state, data) {
    state.isCollect = data.state
  }
}
const getter = {}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getter
}
